<!DOCTYPE html>
<html lang="en" class="x-admin-sm" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>仲裁员管理页面</title>
    <header th:replace="header::html"></header>
    <link th:href="@{/xadmin/lib/layui/css/layui.css}" rel="stylesheet" type="text/css"/>
    <script th:src="@{/xadmin/lib/layui/layui.js}" type="text/javascript"></script>
</head>

<body>

    <div class="layui-fluid">
        <div class="layui-row  layui-col-space15">
            <div class="layui-col-md12">
                <div class="layui-card">
                    <div class="layui-card-body ">
                        <form class="layui-form  layui-col-space5">
                            <div class="layui-inline layui-show-xs-block">
                                <input type="text" name="aname" id="aname" placeholder="仲裁员名称关键字" autocomplete="off"
                                       class="layui-input">
                            </div>
                            <div class="layui-inline layui-show-xs-block">
                                <input type="text" name="aaccount" id="aaccount" placeholder="仲裁员账号关键字" autocomplete="off"
                                       class="layui-input">
                            </div>
                            <div class="layui-inline">
                                <div class="layui-input-inline">
                                    <select name="userStatus" id="userStatus" class="layui-select">
                                        <option value="" selected="selected">--当前状态--</option>
                                        <option value="1">启用</option>
                                        <option value="2">禁用</option>
                                    </select>
                                </div>
                            </div>
                            <div class="layui-inline layui-show-xs-block">
                                <button class="layui-btn" lay-submit="" lay-filter="search"><i
                                        class="layui-icon">&#xe615;</i></button>
                            </div>
                        </form>
                        <br>
                        <div class="layui-inline layui-show-xs-block">
                            <button class="layui-btn layui-btn-xs layui-btn-normal" onclick="xadmin.open('新增仲裁员','/api-back/arbitration/openAdd')"><i
                                    class="layui-icon">新增仲裁员&#xe654;</i></button>
                        </div>
                    </div>
                    <div class="layui-card-body ">
                        <table class="layui-hide" id="arbitrationTable" lay-filter="arbitrationTable" ></table>
                    </div>
                    <script type="text/html" id="barDemo">
                        {{#  if(d.pid ===1){ }}
                        <a class="layui-btn layui-btn-xs layui-btn-danger" lay-event="adiasble" >禁用</a>
                        {{#  } else { }}
                        <a class="layui-btn layui-btn-xs" lay-event="aenable" >启用</a>
                        {{#  } }}
                        <a class="layui-btn layui-btn-xs layui-btn-normal" lay-event="repass" >重置密码</a>
                    </script>
                </div>
            </div>
        </div>
    </div>

</body>
<script>
	layui.use(['table','form','layer'], function () {
		var table = layui.table,
            layer=layui.layer,
			form = layui.form;
		table.render({
			elem: '#arbitrationTable'
			, url: '/api-back/arbitration/userTable' //数据接口
			, page: true //开启分页
			, cellMinWidth: 80 //全局定义常规单元格的最小宽度
			, limits:[10,20]
			, limit:10
			, response: {
				dataName: 'datas' //规定数据列表的字段名称，默认：data
			}
			, cols: [
				[
					{type:'numbers' ,align:'center'}
					,{field:'uid', align:'center',title: '用户id',style:'display:none;'}
					,{field:'uname', align:'center',width: '15%', title: '昵称'}
					,{field:'uaccount', align:'center',width: '13%', title: '账号'}
					,{field:'uphone', align:'center',width: '13%', title: '手机'}
					,{field:'uaddress', align:'center',width: '25%', title: '地址'}
					,{field:'usex', align:'center',width: '6%', title: '性别'}
					,{field:'pid', align:'center',width: '10%', title: '状态',templet:function (res) {
                        if (res.pid===1)
                        	return "启用"
                        else
                        	return "禁用"
					}}
					,{ fixed: 'right', title: '操作',  align: 'center',width: 180, toolbar: '#barDemo'}
				]
			],
			done: function () {
				//checkPermission();
			}

		});
		$('table.layui-table thead tr th:eq(1)').addClass('layui-hide');//隐藏的曝光表id表头
		//监听行工具事件
		table.on('tool(arbitrationTable)', function(obj) { //注：tool 是工具条事件名，test 是 table 原始容器的属性 lay-filter="对应的值"
			var data = obj.data ,//获得当前行数据
				layEvent = obj.event; //获得 lay-event 对应的值
                uid=data.uid;
			if(layEvent === 'adiasble') {
				layer.confirm('确定要禁用该仲裁员吗？',function (index) {
					$.ajax({
						type:"post",
						url:'/api-back/arbitration/arbitratorOperate',
						data:{"uid":uid,"operate":"disable"},
						success:function (msg) {
							if (msg === "success") {
								layer.msg("禁用成功",{icon:1});
								$(".layui-laypage-btn")[0].click();
							} else {
								layer.msg("禁用失败，请重试",{icon:2})
							}
						},
						error:function (msg) {
							layer.open({
								type:2,
								content: "/404.html",
								area:['1000px','600px'],
								title:'权限不允许进行访问'
							})
						}
					})
				})
			}else if(layEvent === 'aenable') {
				layer.confirm('确定要启用该仲裁员吗？',function (index) {
					$.ajax({
						type:"post",
						url:'/api-back/arbitration/arbitratorOperate',
						data:{"uid":uid,"operate":"enable"},
						success:function (msg) {
							if (msg === "success") {
								layer.msg("启用成功",{icon:1});
								$(".layui-laypage-btn")[0].click();
							} else {
								layer.msg("启用失败，请重试",{icon:2})
							}
						},
						error:function (msg) {
							layer.open({
								type:2,
								content: "/404.html",
								area:['1000px','600px'],
								title:'权限不允许进行访问'
							})
						}
					})
				})
			} else if(layEvent === 'repass') {
				layer.confirm('确定要重置仲裁员密码吗？重置后初始密码为123456',function (index) {
					$.ajax({
						type:"post",
						url:'/api-back/arbitration/repass',
						data:{"uid":uid},
						success:function (msg) {
							if (msg === "success") {
								layer.msg("重置成功",{icon:1});
								$(".layui-laypage-btn")[0].click();
							} else {
								layer.msg("重置失败，请重试",{icon:2})
							}
						},
						error:function (msg) {
							layer.open({
								type:2,
								content: "/404.html",
								area:['1000px','600px'],
								title:'权限不允许进行访问'
							})
						}
					})
				})
			}

		});

		//搜索
		form.on('submit(search)', function (data) {
			var field = data.field;
            table.render({
	            elem: '#arbitrationTable'
	            , url: '/api-back/arbitration/userTable' //数据接口
                , page: true //开启分页
	            , limits:[10,20]
	            , limit:10
                , where: {
                    "aname": field.aname,
                    "aaccount": field.aaccount,
                    "userStatus": field.userStatus,
                }
                , response: {
                    dataName: 'datas' //规定数据列表的字段名称，默认：data
                }
                , cols: [
		            [
			            {type:'numbers' ,align:'center'}
			            ,{field:'uid', align:'center',title: '用户id',style:'display:none;'}
			            ,{field:'uname', align:'center',width: '15%', title: '昵称'}
			            ,{field:'uaccount', align:'center',width: '13%', title: '账号'}
			            ,{field:'uphone', align:'center',width: '13%', title: '手机'}
			            ,{field:'uaddress', align:'center',width: '25%', title: '地址'}
			            ,{field:'usex', align:'center',width: '6%', title: '性别'}
			            ,{field:'pid', align:'center',width: '10%', title: '状态',templet:function (res) {
				            if (res.pid===1)
					            return "启用"
				            else
					            return "禁用"
			            }}
			            ,{ fixed: 'right', title: '操作',  align: 'center',width: 180, toolbar: '#barDemo'}
		            ]
                ]
            });
            $('table.layui-table thead tr th:eq(1)').addClass('layui-hide');//隐藏的曝光表id表头
			return false;
		});
		//checkPermission();
	});

</script>
</html>